package cn.com.thinker.core.aop.monitor;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Created by crazyHC on 2017/6/9.
 */
@Aspect
@Component
public class ServiceMonitor {

    @Pointcut("execution(* cn.com.thinker..*Service.*(..))")
    public void executeService(){}

    @Before(value = "executeService()")
    public void before(JoinPoint joinPoint) {
        System.out.println("Before Advise Completed: " + joinPoint);
    }

    @Around(value = "executeService()")
    public Object  around(ProceedingJoinPoint pjp) throws  Throwable{
        System.out.println("Around Advise Start:" + pjp);
        Object proceed = pjp.proceed();
        System.out.println("Around Advise Completed:" +pjp);
        return proceed;
    }

    @AfterReturning("executeService()")
    public void logServiceAccess(JoinPoint joinPoint) {
        System.out.println("AfterReturning Advise Completed: " + joinPoint);
    }

    @AfterThrowing(value = "executeService()")
    public void afterThrowing(JoinPoint joinPoint) {
        System.out.println("AfterThrowing Advise Completed:"+ joinPoint);
    }

    @After(value = "executeService()")
    public void after(JoinPoint joinPoint) {
        System.out.println("After Advise Completed:"+joinPoint);
    }

}